package com.berchen.offer;

import java.util.HashSet;
import java.util.Set;

/**
 *  求出字符串的不含重复字符的最长子串
 */
public class Test21 {

    public static void main(String[] args){

        int abcabcbb = lengthOfLongestSubstring("abcabcbb");
        System.out.println(abcabcbb);
    }


    public static int lengthOfLongestSubstring(String s) {

        int max=0;
        char[] chars = s.toCharArray();

        for (int i = 0; i < chars.length; i++) {
            if(max>=(chars.length-i)){
                break;
            }
            int temp=0;
            Set<Character> set=new HashSet<>();
            for (int j = i; j < chars.length; j++) {
                if(set.add(chars[j])){
                    temp++;
                }else {
                    break;
                }
            }
            max=max>=temp?max:temp;
        }

        return max;
    }
}
